package com.xiaoshuidi.cloud.module.guanwang.controller.app.apartment;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.tenant.core.context.TenantContextHolder;
import com.xiaoshuidi.cloud.module.guanwang.controller.app.apartment.vo.ChoiceRoomLayoutReqVO;
import com.xiaoshuidi.cloud.module.guanwang.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.guanwang.service.index.WebApartmentService;
import com.xiaoshuidi.cloud.module.rooms.api.home.vo.*;
import com.xiaoshuidi.cloud.module.rooms.api.map.vo.GetMapRespApiVO;
import com.xiaoshuidi.cloud.module.rooms.api.map.vo.MapFindSearchReqApiVO;
import com.xiaoshuidi.cloud.module.rooms.api.map.vo.MetroRouteRespApiVO;
import com.xiaoshuidi.cloud.module.rooms.api.map.vo.MetroSiteRespApiVO;
import com.xiaoshuidi.cloud.module.rooms.api.roomlayout.vo.GetRoomLayoutByApartmentRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import java.util.List;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Slf4j
@RestController
@RequestMapping(ApiConstants.NAME + "/web-apartment")
public class AppWebApartmentController {
    @Resource
    private WebApartmentService webApartmentService;

    @PermitAll
    @GetMapping("/recommend-apartment")
    @Parameter(name = "apartmentId", description = "要排除的门店")
    @Operation(summary = "获取营销管理-app配置")
    public CommonResult<Object> recommendApartment(Integer id, Long apartmentId){
        return webApartmentService.recommendApartment(id, apartmentId);
    }

    @PermitAll
    @PostMapping("/choice-room-layout")
    @Operation(summary = "精选房型")
    public CommonResult<List<GetRoomLayoutByApartmentRespVO>> choiceRoomLayout(){
        return webApartmentService.choiceRoomLayout();
    }

    @PermitAll
    @GetMapping("/get-apartment-info")
    @Parameter(name = "apartmentId", description = "门店id")
    @Operation(summary = "门店详情")
    public CommonResult<ApartmentInfoRespApiVO> getApartmentInfo(Long apartmentId){
        return webApartmentService.getApartmentInfo(apartmentId);
    }

    @PermitAll
    @Operation(summary = "散房详情")
    @Parameters({
            @Parameter(name = "roomHouseId", description = "房源id"),
    })
    @GetMapping("/get-room-house-info")
    public CommonResult<RoomHouseInfoRespApiVO> getRoomHouseInfo(@RequestParam("roomHouseId") Long roomHouseId) {
        return webApartmentService.getRoomHouseInfo(roomHouseId);
    }

    @Operation(summary = "房源详情-同房源其他房间")
    @Parameters({
            @Parameter(name = "roomHouseId", description = "房源id"),
    })
    @GetMapping("/other-rooms-in-the-same-listing")
    @PermitAll
    public CommonResult<List<OtherRoomsInTheSameListingRespApiVO>> otherRoomsInTheSameListing(@RequestParam("roomHouseId") Long roomHouseId) {
        Long tenantId = TenantContextHolder.getTenantId();
        return webApartmentService.otherRoomsInTheSameListing(roomHouseId, tenantId);
    }

    @PermitAll
    @Operation(summary = "房源详情-推荐附近房源")
    @Parameters({
            @Parameter(name = "roomHouseId", description = "房源id"),
    })
    @GetMapping("/recommend-listings-near-you")
    public CommonResult<List<OtherRoomsInTheSameListingRespApiVO>> recommendListingsNearYou(@RequestParam("roomHouseId") Long roomHouseId) {
        Long tenantId = TenantContextHolder.getTenantId();
        return webApartmentService.recommendListingsNearYou(roomHouseId, tenantId);
    }

    @PermitAll
    @Operation(summary = "社区-房型详情")
    @Parameters({
            @Parameter(name = "apartmentId", description = "门店id"),
            @Parameter(name = "layoutId", description = "房型id")
    })
    @GetMapping("/get-layout-info")
    public CommonResult<GetLayoutInfoRespApiVO> getLayoutInfo(@RequestParam("apartmentId") Long apartmentId, @RequestParam("layoutId") Long layoutId) {
        return webApartmentService.getLayoutInfo(apartmentId, layoutId);
    }

    @PermitAll
    @Operation(summary = "地图找房")
    @Parameters({
            @Parameter(name = "maxLongitude", description = "最大经度", required = true),
            @Parameter(name = "minLongitude", description = "最小经度", required = true),
            @Parameter(name = "maxLatitude", description = "最大纬度", required = true),
            @Parameter(name = "minLatitude", description = "最小纬度", required = true),
            @Parameter(name = "isConcentrated", description = "是否集中式", required = true),
            @Parameter(name = "district", description = "区域"),
            @Parameter(name = "monthRentalMin", description = "租金范围-下限"),
            @Parameter(name = "monthRentalMax", description = "租金范围-上限"),
            @Parameter(name = "longitude", description = "地铁站经度"),
            @Parameter(name = "latitude", description = "地铁站纬度"),
            @Parameter(name = "isWhole", description = "出租方式,是否整租 true:整租 false:合租"),
            @Parameter(name = "bedRoomNum", description = "户型-几室 1:一室 2:二室 3:三室 4:四室 5:其他"),
            @Parameter(name = "publicFacilities", description = "特色需求(公共设施)"),
            @Parameter(name = "roomHouseState", description = "房源状态 1：可租房源 2：全部房源", required = true),
            @Parameter(name = "zoom", description = "缩放等级", required = true),
    })
    @GetMapping("/map-find-room")
    public CommonResult<List<GetMapRespApiVO>> mapFindRoom(@RequestParam("maxLongitude") Double maxLongitude,
                                                           @RequestParam("minLongitude") Double minLongitude,
                                                           @RequestParam("maxLatitude") Double maxLatitude,
                                                           @RequestParam("minLatitude") Double minLatitude,
                                                           @RequestParam("isConcentrated") Boolean isConcentrated,
                                                           @RequestParam(value = "district",required = false) String district,
                                                           @RequestParam(value = "monthRentalMin",required = false) Double monthRentalMin,
                                                           @RequestParam(value = "monthRentalMax",required = false) Double monthRentalMax,
                                                           @RequestParam(value = "longitude",required = false) Double longitude,
                                                           @RequestParam(value = "latitude",required = false) Double latitude,
                                                           @RequestParam(value = "isWhole",required = false) Boolean isWhole,
                                                           @RequestParam(value = "bedRoomNum",required = false) Integer bedRoomNum,
                                                           @RequestParam(value = "publicFacilities",required = false) String publicFacilities,
                                                           @RequestParam("roomHouseState") String roomHouseState,
                                                           @RequestParam("zoom") Double zoom){
        Long tenantId = TenantContextHolder.getTenantId();
        return webApartmentService.mapFindRoom(maxLongitude, minLongitude, maxLatitude, minLatitude, zoom, tenantId,
                isConcentrated, district, monthRentalMin, monthRentalMax, longitude, latitude, isWhole, bedRoomNum, publicFacilities, roomHouseState);
    }

    @PermitAll
    @Operation(summary = "地图找房-搜索")
    @Parameters({
            @Parameter(name = "searchBox", description = "搜索框内容"),
    })
    @GetMapping("/map-find-search")
    public CommonResult<PageResult<GetMapRespApiVO>> mapFindSearch(MapFindSearchReqApiVO reqVO){
        Long tenantId = TenantContextHolder.getTenantId();
        return webApartmentService.mapFindSearch(reqVO.getSearchBox(), reqVO.getIsConcentrated(), reqVO.getRoomHouseState(), reqVO.getPageNo(), reqVO.getPageSize(), tenantId);
    }

    @PermitAll
    @Operation(summary = "获取所有地铁线路")
    @GetMapping("/metro-route")
    public CommonResult<List<MetroRouteRespApiVO>> getMetroRoute(){
        return webApartmentService.getMetroRoute();
    }

    @PermitAll
    @Operation(summary = "获取地铁线路下的站点")
    @GetMapping("/metro-site")
    public CommonResult<List<MetroSiteRespApiVO>> getMetroSite(@RequestParam("id") Long id){
        return webApartmentService.getMetroSite(id);
    }


    @PermitAll
    @Operation(summary = "集中式-找房")
    @Parameters({
            @Parameter(name = "searchBox", description = "搜索框查询"),
            @Parameter(name = "district", description = "区域"),
            @Parameter(name = "monthRentalMin", description = "租金范围-下限"),
            @Parameter(name = "monthRentalMax", description = "租金范围-上限"),
            @Parameter(name = "longitude", description = "地铁站经度"),
            @Parameter(name = "latitude", description = "地铁站纬度"),
            @Parameter(name = "sortRule", description = "排序规则 1:推荐排序 2:最新发布 3:价格升序 4:价格降序 5:面积升序 6:面积降序"),
            @Parameter(name = "isWhole", description = "出租方式,是否整租 true:整租 false:合租"),
            @Parameter(name = "bedRoomNum", description = "户型-几室 1:一室 2:二室 3:三室 4:四室 5:其他"),
            @Parameter(name = "publicFacilities", description = "特色需求(公共设施)", example = "独立卫生间"),
            @Parameter(name = "lon", description = "用户所在经度"),
            @Parameter(name = "lat", description = "用户所在纬度"),
    })
    @GetMapping( "/concentrated-find-house")
    public CommonResult<PageResult<ConcentratedFindHouseRespApiVO>> concentratedFindHouse(@RequestParam(value = "searchBox", required = false) String searchBox,
                                                                                          @RequestParam(value = "district", required = false) String district,
                                                                                          @RequestParam(value = "monthRentalMin", required = false) Double monthRentalMin,
                                                                                          @RequestParam(value = "monthRentalMax", required = false) Double monthRentalMax,
                                                                                          @RequestParam(value = "longitude",required = false) Double longitude,
                                                                                          @RequestParam(value = "latitude",required = false) Double latitude,
                                                                                          @RequestParam(value = "sortRule",required = false) Integer sortRule,
                                                                                          @RequestParam(value = "isWhole",required = false) Boolean isWhole,
                                                                                          @RequestParam(value = "bedRoomNum",required = false) Integer bedRoomNum,
                                                                                          @RequestParam(value = "publicFacilities",required = false) String publicFacilities,
                                                                                          @RequestParam(value = "lon",required = false) String lon,
                                                                                          @RequestParam(value = "lat",required = false) String lat,
                                                                                          @RequestParam("pageNum") Integer pageNum,
                                                                                          @RequestParam("pageSize") Integer pageSize){
        return webApartmentService.concentratedFindHouse(searchBox,district,monthRentalMin,monthRentalMax,longitude,latitude,sortRule,isWhole,bedRoomNum,publicFacilities,lon,lat,pageNum,pageSize);

    }

    @PermitAll
    @Operation(summary = "分散式-找房")
    @Parameters({
            @Parameter(name = "searchBox", description = "搜索框查询"),
            @Parameter(name = "district", description = "区域"),
            @Parameter(name = "monthRentalMin", description = "租金范围-下限"),
            @Parameter(name = "monthRentalMax", description = "租金范围-上限"),
            @Parameter(name = "longitude", description = "地铁站经度"),
            @Parameter(name = "latitude", description = "地铁站纬度"),
            @Parameter(name = "sortRule", description = "排序规则 1:推荐排序 2:最新发布 3:价格升序 4:价格降序 5:面积升序 6:面积降序"),
            @Parameter(name = "isWhole", description = "出租方式,是否整租 true:整租 false:合租"),
            @Parameter(name = "bedRoomNum", description = "户型-几室 1:一室 2:二室 3:三室 4:四室 5:其他"),
            @Parameter(name = "publicFacilities", description = "特色需求(公共设施)", example = "独立卫生间"),
            @Parameter(name = "pageNum"),
            @Parameter(name = "pageSize"),
    })
    @GetMapping(  "/no-concentrated-find-house")
    public CommonResult<PageResult<NoConcentratedFindHouseRespApiVO>> noConcentratedFindHouse(@RequestParam(value = "searchBox",required = false) String searchBox,
                                                                                              @RequestParam(value = "district",required = false) String district,
                                                                                              @RequestParam(value = "monthRentalMin",required = false) Double monthRentalMin,
                                                                                              @RequestParam(value = "monthRentalMax",required = false) Double monthRentalMax,
                                                                                              @RequestParam(value = "longitude",required = false) Double longitude,
                                                                                              @RequestParam(value = "latitude",required = false) Double latitude,
                                                                                              @RequestParam(value = "sortRule",required = false) Integer sortRule,
                                                                                              @RequestParam(value = "isWhole",required = false) Boolean isWhole,
                                                                                              @RequestParam(value = "bedRoomNum",required = false) Integer bedRoomNum,
                                                                                              @RequestParam(value = "publicFacilities",required = false) String publicFacilities,
                                                                                              @RequestParam(value = "roomAreaId",required = false) Long roomAreaId,
                                                                                              @RequestParam("pageNum") Integer pageNum,
                                                                                              @RequestParam("pageSize") Integer pageSize){
        return webApartmentService.noConcentratedFindHouse(searchBox,district,monthRentalMin,monthRentalMax,longitude,latitude,sortRule,isWhole,bedRoomNum,publicFacilities,roomAreaId,pageNum,pageSize);
    }
}
